package com.itheima.job;

import java.util.Scanner;

public class MyRunnable02 implements Runnable{
    @Override
    public void run() {
        int i;
        synchronized (this) {
            Scanner sc = new Scanner(System.in);
            System.out.println("输入您要运算的阶乘：");
             i = sc.nextInt();
        }
        long result = jiecheng(i);

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"线程计算的"+i+"的阶乘为："+result);
    }

    private long jiecheng(int i) {
        if (i==1){
            return 1;
        }else {
            return jiecheng(i-1)*i;
        }
    }

}
